package com.yxe.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 缴费种类
 */
@Getter
@AllArgsConstructor
public enum PayType {

    DIANFEI("电费缴费", 1),
    SHUIFEI("水费缴费", 2),
    RANQIFEI("燃气费缴费", 3),
    FANGZU("房租缴费", 4);

    private String description;//描述
    private Integer code;//编号

    //根据code值返回枚举对象
    public static PayType of(Integer code){
        //判断code不为空
        Objects.requireNonNull(code);

        //返回所有的枚举对象
        return Stream.of(values())
                .filter(PayType -> PayType.code == code)//判断传入的code值
                .findFirst()//获取值
                .orElseThrow( () -> new IllegalArgumentException(code + " is not exist"));

    }
}
